package com.byb.server.service.impl;

import com.byb.server.service.WcClaimCasesService;
import com.byb.server.domain.WcClaimCases;
import com.byb.server.repository.WcClaimCasesRepository;
import com.byb.server.repository.search.WcClaimCasesSearchRepository;
import com.byb.server.service.dto.WcClaimCasesDTO;
import com.byb.server.service.mapper.WcClaimCasesMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


import static org.elasticsearch.index.query.QueryBuilders.*;

/**
 * Service Implementation for managing WcClaimCases.
 */
@Service
@Transactional
public class WcClaimCasesServiceImpl implements WcClaimCasesService{

    private final Logger log = LoggerFactory.getLogger(WcClaimCasesServiceImpl.class);

    private final WcClaimCasesRepository wcClaimCasesRepository;

    private final WcClaimCasesMapper wcClaimCasesMapper;

    private final WcClaimCasesSearchRepository wcClaimCasesSearchRepository;
    public WcClaimCasesServiceImpl(WcClaimCasesRepository wcClaimCasesRepository, WcClaimCasesMapper wcClaimCasesMapper, WcClaimCasesSearchRepository wcClaimCasesSearchRepository) {
        this.wcClaimCasesRepository = wcClaimCasesRepository;
        this.wcClaimCasesMapper = wcClaimCasesMapper;
        this.wcClaimCasesSearchRepository = wcClaimCasesSearchRepository;
    }

    /**
     * Save a wcClaimCases.
     *
     * @param wcClaimCasesDTO the entity to save
     * @return the persisted entity
     */
    @Override
    public WcClaimCasesDTO save(WcClaimCasesDTO wcClaimCasesDTO) {
        log.debug("Request to save WcClaimCases : {}", wcClaimCasesDTO);
        WcClaimCases wcClaimCases = wcClaimCasesMapper.toEntity(wcClaimCasesDTO);
        wcClaimCases = wcClaimCasesRepository.save(wcClaimCases);
        WcClaimCasesDTO result = wcClaimCasesMapper.toDto(wcClaimCases);
        //wcClaimCasesSearchRepository.save(wcClaimCases);
        return result;
    }

    /**
     *  Get all the wcClaimCases.
     *
     *  @param pageable the pagination information
     *  @return the list of entities
     */
    @Override
    @Transactional(readOnly = true)
    public Page<WcClaimCasesDTO> findAll(Pageable pageable) {
        log.debug("Request to get all WcClaimCases");
        return wcClaimCasesRepository.findAll(pageable)
            .map(wcClaimCasesMapper::toDto);
    }

    /**
     *  Get one wcClaimCases by id.
     *
     *  @param id the id of the entity
     *  @return the entity
     */
    @Override
    @Transactional(readOnly = true)
    public WcClaimCasesDTO findOne(Long id) {
        log.debug("Request to get WcClaimCases : {}", id);
        WcClaimCases wcClaimCases = wcClaimCasesRepository.findOne(id);
        return wcClaimCasesMapper.toDto(wcClaimCases);
    }

    /**
     *  Delete the  wcClaimCases by id.
     *
     *  @param id the id of the entity
     */
    @Override
    public void delete(Long id) {
        log.debug("Request to delete WcClaimCases : {}", id);
        wcClaimCasesRepository.delete(id);
        //wcClaimCasesSearchRepository.delete(id);
    }

    /**
     * Search for the wcClaimCases corresponding to the query.
     *
     *  @param query the query of the search
     *  @param pageable the pagination information
     *  @return the list of entities
     */
    @Override
    @Transactional(readOnly = true)
    public Page<WcClaimCasesDTO> search(String query, Pageable pageable) {
        log.debug("Request to search for a page of WcClaimCases for query {}", query);
        Page<WcClaimCases> result = wcClaimCasesSearchRepository.search(queryStringQuery(query), pageable);
        return result.map(wcClaimCasesMapper::toDto);
    }
}
